<?php
include_once 'config.php';

abstract class Index{
	
	public static function main(){			
		spl_autoload_register('Config::classLoader');
		set_exception_handler('Config::exceptionHandler');
		Config::init();
		session_start();
		if(empty($_POST) && empty($_GET)){			
			if (!empty($_SESSION) and isset($_SESSION['user_id'])){
				$objBO_User = DA_User::getUserById($_SESSION['user_id']);			
				if($objBO_User !== false){
					UI_App::render($objBO_User);
				}			
			}else {
				UI_Login::main();
			}			
		}
		elseif( isset($_POST['user']) and isset($_POST['pass']) ){
			$objBO_User = DA_User::getUserByNameAndPass($_POST['user'],$_POST['pass']);			
			if($objBO_User !== false){
				$_SESSION['user_id']= $objBO_User->id;
				UI_App::render($objBO_User);
			}
			else{
				UI_Login::main(UI_Error::InvalidUser);			
			}			
		}
		elseif( Config::debugMode and isset($_GET['unitTest']) ){
			UnitTest::main($_GET);
		}	
	}	
}

Index::main();

?>